<template>
	<gracePage statusBarBG="#EB5D4B" :headerHeight="0">
		<view slot="gHeader" class="grace-border-b">
			<graceHeader background="#EB5D4B" style="height: 88rpx;">
				<view class="grace-header-body">
					<!-- 返回按钮 -->
					<view class="grace-header-icons grace-icons grace-white icon-arrow-left" @tap="goback"></view>
					<!-- 中间内容 -->
					<view class="grace-header-content-noflex" style="text-align: center;color: #FFFFFF;font-size: 30rpx;">我的地址</view>
					<text class="grace-icons icon-add" @tap="addAddress" style="color: #FFFFFF;margin-right: 40rpx;font-weight: 600;"></text>
				</view>
			</graceHeader>
		</view>
		<view slot="gBody" class="grace-body">
			<view class="grace-list">
				<view class="grace-list-items grace-border-b" v-for="(item, index) in forData" :key="index" @tap="selectAddress(item)">
					<view class="grace-list-body">
						<view class="grace-list-title" style="justify-content: flex-start;">
							<text class="grace-list-title-text">{{item.name}}</text>
							<text class="grace-list-title-desc" style="line-height: 40rpx;">{{item.phone}}</text>
						</view>
						<view class="grace-list-body-desc">{{item.province+item.city+item.district+item.address}}</view>
					</view>
					<text class="grace-list-arrow-right grace-icons icon-write" style="margin-right: 20rpx;" @tap.stop="editAddress(item)"></text>
				</view>
			</view>
		</view>
	</gracePage>
</template>
<script>
import gracePage from '../../graceUI/components/gracePage.vue';
import graceHeader from '../../graceUI/components/graceHeader.vue';
export default {
	data() {
		return {
			forData: [], //模拟的循环数据
			type:""
		};
	},
	onLoad(option) {
		this.type = option.type
	},
	onShow() {
		this.getData()
	},
	methods: {
		selectAddress(data) {
			if(this.type==1) {
				uni.setStorage({
					key:"currentAddress",
					data: JSON.stringify(data),
					success:function(){
						uni.navigateBack({
						    delta: 1
						});
					}
				})
			}
		},
		getData:function(){
			this.gRequest.get('/orders/getaddresslist', {
				member_id:JSON.parse(uni.getStorageSync("userInfo")).member_id
			}, res => {
				this.setData({ forData: res.data });
			});
		},
		editAddress: function(data) {
			uni.setStorage({
				key:"addressData",
				data:JSON.stringify(data),
				success:()=>{
					uni.navigateTo({
						url: '../my/addAddress'
					});
				}
			})
		},
		addAddress: function() {
			uni.removeStorage({
				key:"addressData",
				success:()=>{
					uni.navigateTo({
						url: '../my/addAddress'
					});
				}
			})
			uni.navigateTo({
				url: '../my/addAddress'
			});
		},
		goback: function() {
			uni.navigateBack({});
		}
	},
	components: { gracePage, graceHeader }
};
</script>
<style>
.grace-body {
	margin-top: 100rpx;
}
</style>
